Re: [GENERAL] How to do this in SQL?

Поиск
Список
Период
Сортировка
От Stuart Rison
Тема Re: [GENERAL] How to do this in SQL?
Дата
Msg-id v04003a07b326a26d4f2e@[128.40.242.190]
обсуждение исходный текст
Ответ на How to do this in SQL?  (Chris Bitmead <chris.bitmead@bigfoot.com>)
Список pgsql-general
>Let's say I had a table...
>CREATE TABLE book (
>   author oid,
>   name text );
>and...
>CREATE TABLE author (
>   name text );
>
>and I wanted to create a book pointing to author with name 'Tolstoy'. I
>want to do something like...
>
>INSERT INTO book(name,author) values('War and Peace',
>      (SELECT oid FROM author WHERE name = 'Tolstoy'));
>
>but this doesn't work. What is the correct syntax?
>

try \h insert in psql for a description of the correct syntax.

Your query becomes:

INSERT INTO book(author,name)
    SELECT oid,'War and Peace'
    FROM author
    WHERE name='Tolstoy';

Stuart.


+-------------------------+--------------------------------------+
| Stuart Rison            | Ludwig Institute for Cancer Research |
+-------------------------+ 91 Riding House Street               |
| Tel. (0171) 878 4041    | London, W1P 8BT, UNITED KINGDOM.     |
| Fax. (0171) 878 4040    | stuart@ludwig.ucl.ac.uk              |
+-------------------------+--------------------------------------+



В списке pgsql-general по дате отправления:

Предыдущее
От: Chris Bitmead
Дата:
Сообщение: How to do this in SQL?
Следующее
От: "Jackson, DeJuan"
Дата:
Сообщение: RE: [GENERAL] Performance